<template>
  <FormView
    v-model="entity"
    :title="entity.id ? '成员信息' : '新建成员'"
    :toolbar-attrs="{ buttons: ['back', { save: isEnabled, edit: isDisabled }, 'cancel'] }"
    :toolbar-listeners="{ save: persist }">
    <template #toolbar-right> </template>
    <FormHolder ref="form" label-width="130px" :disabled="isDisabled" :model="entity">
      <FormItemGroup block-title="基本信息">
        <InputProjectMember v-model="entity.name" placeholder="请输入姓名" prop="name" label="姓名" required @select="setupForm" />
        <FormSelect v-model="entity.gender" prop="gender" label="性别" required dict-type="gender"/>
        <FormDatePicker v-model="entity.birthday" prop="birthday" label="出生日期" required />
        <FormInput v-model="entity.idType" prop="idType" label="证件类型" required />
        <FormInput v-model="entity.idNo" prop="idNo" label="证件号码" required />
        <FormSelect v-model="entity.technicalTitles" prop="technicalTitles" label="专业技术职称" dict-type="technical_titles" required />
        <FormInput v-model="entity.duties" prop="duties" label="职务" required />
        <FormInput v-model="entity.education" prop="education" label="最高学历" required />
        <FormInput v-model="entity.speciality" prop="speciality" label="专业" required />
        <FormSelect v-model="entity.workMoth" prop="workMoth" label="投入本项目的全部工作时间（人月）" :start="1" :end="99" />
        <FormSelect v-model="entity.memberType" prop="memberType" label="人员分类" required dict-type="project_member_type"/>
        <FormInput v-if="entity.memberType==='其他人员'" v-model="entity.memberDesc" prop="memberDesc" required label="人员说明"/>
        <FormSelect v-model="entity.hasWageIncome" prop="hasWageIncome" label="是否有工资性收入" dict-type="yes_no" />
        <FormInput v-model="entity.workUnit" prop="workUnit" label="工作单位" required />
        <FormInput v-model="entity.projectName" prop="projectName" label="所属项目名称" />
        <!--<FormInput v-model="entity.topic" prop="topic" label="所属课题" />-->
      </FormItemGroup>
    </FormHolder>
  </FormView>
</template>

<script>
  import { create, load, save, update } from './api'
  import form from '@/vue/mixin/form'
  import { copyMember } from '@/module/tech-project/project-manage'
  import InputProjectMember from '@/module/tech-project/project-manage/member/InputProjectMember.vue'

  export default {
    name: 'ProjectMemberForm',
    components: { InputProjectMember },
    docType: '',
    relativeViewId: 'ProjectMemberView',
    mixins: [form],
    data() {
      return {
        entity: {
          id: null,
          unid: null,
          createTime: null,
          createBy: null,
          createId: null,
          deptId: null,
          deptFullName: null,
          updateTime: null,
          updateId: null,
          updateBy: null,
          tenantId: null,
          delFlag: null,
          name: null,
          gender: null,
          birthday: null,
          idType: null,
          idNo: null,
          technicalTitles: null,
          duties: null,
          education: null,
          speciality: null,
          workMoth: null,
          memberType: null,
          memberDesc: null,
          hasWageIncome: null,
          workUnit: null,
          projectId: null,
          projectName: null,
          topic: null,
          status: null
        }
      }
    },
    methods: {
      create,
      load,
      save,
      update,
      async initEntity(id) {
        this.entity = await this.loadEntity(id)
      },
      setupForm(source) {
        copyMember(this.entity, source)
      }
    }
  }
</script>
